package com.ytjj.qmyx.data.service.impl;

import com.ytjj.common.constants.StatisticsConstants;
import com.ytjj.common.dto.mqdto.SkipStatisticsDto;
import com.ytjj.qmyx.data.constants.MongoCollectionNameConstants;
import com.ytjj.qmyx.data.model.mongo.SkipStatistics;
import com.ytjj.qmyx.data.service.SkipStatisticsService;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 *
 *  *
 **/
@Service
public class SkipStatisticsServiceImpl implements SkipStatisticsService {


    @Resource
    private MongoTemplate mongoTemplate;

    @Resource
    private RedisTemplate redisTemplate;

    @Override
    public void skipStatistics(SkipStatisticsDto skipStatisticsDto) {
        SkipStatistics skipStatistics = new SkipStatistics();
        skipStatistics.copyProperty(skipStatisticsDto);

        mongoTemplate.save(skipStatistics);

        redisTemplate.opsForHash().increment(StatisticsConstants.SKIP_NUM + skipStatistics.getDayTime(), skipStatistics.getChannel(), 1);
        redisTemplate.opsForHash().increment(StatisticsConstants.SKIP_NUM + skipStatistics.getDayTime(), "all", 1);

        mongoTemplate.save(skipStatistics, MongoCollectionNameConstants.SKIP+skipStatistics.getDayTime());
    }
}
